<template>
    <div>
        <el-form :model="doctorInfo" ref="form" label-width="120px" :inline="false">
            <el-form-item label="医生账号">
                <el-input v-model="doctorInfo.account"></el-input>
            </el-form-item>
            <el-form-item label="账号权限">
                <el-input v-model="doctorInfo.name"></el-input>
            </el-form-item>
            <el-form-item label="旧密码">
                <el-input v-model="doctorInfo.password" type="password"></el-input>
            </el-form-item>
            <el-form-item label="新密码">
                <el-input v-model="doctorInfo.password" type="password"></el-input>
            </el-form-item>
            <el-form-item label="姓名">
                <el-input v-model="doctorInfo.name"></el-input>
            </el-form-item>
            <el-form-item label="身份证号码">
                <el-input v-model="doctorInfo.idcard"></el-input>
            </el-form-item>
            <el-form-item label="手机号">
                <el-input v-model="doctorInfo.phone"></el-input>
            </el-form-item>
            <el-form-item label="所属科室">
                <el-select v-model="doctorInfo.department" class="m-2" :placeholder="doctorInfo.department">
                    <el-option v-for="item in data.options" :key="item.id" :label="item.nmae" :value="item.name" />
                </el-select>
            </el-form-item>
            <el-form-item label="更改照片">
                <el-upload class="avatar-uploader" action="http://129.211.169.131:21010/users/uploadheader"
                    :show-file-list="false" :on-success="handleAvatarSuccess">
                    <img v-if="doctorInfo.headurl" :src="doctorInfo.headurl" class="avatar" style="width: 120px;" />
                    <el-icon v-else class="avatar-uploader-icon">
                        <Plus />
                    </el-icon>
                </el-upload>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="edit">修改</el-button>
                <el-button>取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup lang="ts">
import { departnamesReq } from '@/api/common.api';
import { getbyidReq } from '@/api/doctor.api';
import { userEditReq } from '@/api/user.api';
import { IDoctor } from '@/types/doctor.type';
import { ElMessage } from 'element-plus';
import { reactive, ref } from 'vue';
// 获取id
const id = localStorage.getItem('info')

let doctorInfo = ref<any>({})
let data = reactive<any>({
    options: []
})

const doctorData = () => {
    getbyidReq(Number(id)).then(res => {
        doctorInfo.value = res.data.data[0]
    })
}

doctorData()

// 获取所有的科室信息
departnamesReq().then(res => {
    data.options = res.data.data
})
// 修改个人信息
const edit = () => {
    userEditReq(doctorInfo.value).then(res => {
        if (res.data.code) {
            ElMessage.success(res.data.msg)
            doctorData()
        }
    })
}

// 上传头像成功
const handleAvatarSuccess = (response: any) => {
    doctorInfo.value.headurl = response.header_url
    doctorInfo.value.head = response.header
}




</script>

<style scoped></style>